function okOnClick() {
	var tabletools = TableTools.fnGetInstance('table');
	var selectedValue = '';
	var editItemCode = '';
	var editItemName = '';
	var editItemDescription = '';
	var editPrice = 0.0;
	var editOrigLocation = '';
	var editCategory = '';
	var editIcon = '';
	var editAttribute = '';
	var editSuspended = '';
	var editBrand = '';

	for ( var i = 0; i < tabletools.fnGetSelected().length; i++) {
		var value = tabletools.fnGetSelected()[i].getElementsByTagName("td")[0].innerHTML;
		selectedValue += value + ';';
		// selectedValue = value;
		editItemCode = value;
		editItemName = tabletools.fnGetSelected()[i].getElementsByTagName("td")[1].innerHTML;
		editItemDescription = tabletools.fnGetSelected()[i]
				.getElementsByTagName("td")[2].innerHTML;
		editPrice = tabletools.fnGetSelected()[i].getElementsByTagName("td")[3].innerHTML;
		editOrigLocation = tabletools.fnGetSelected()[i]
				.getElementsByTagName("td")[4].innerHTML;
		editCategory = tabletools.fnGetSelected()[i].getElementsByTagName("td")[5].innerHTML;
		editIcon = tabletools.fnGetSelected()[i].getElementsByTagName("td")[6].innerHTML;
		editIcon = $(editIcon).attr("src");

		// alert(editIcon);
		editSuspended = tabletools.fnGetSelected()[i]
			.getElementsByTagName("td")[8].innerHTML;
		editAttribute = tabletools.fnGetSelected()[i]
				.getElementsByTagName("td")[9].innerHTML;
		editBrand = tabletools.fnGetSelected()[i]
			.getElementsByTagName("td")[10].innerHTML;
	}

	// alert(selectedValue);
	$("[id='items_form:selected_value']").val(selectedValue);
	$("[id='items_form:selected_item_code']").val(editItemCode);
	$("[id='items_form:selected_item_name']").val(editItemName);
	$("[id='items_form:selected_item_description']").val(editItemDescription);
	$("[id='items_form:selected_price']").val(editPrice);
	$("[id='items_form:selected_orig_location']").val(editOrigLocation);
	$("[id='items_form:selected_category']").val(editCategory);
	$("[id='items_form:selected_icon']").val(editIcon);
	$("[id='items_form:selected_attributes']").val(editAttribute);
	$("[id='items_form:selected_suspended']").val(editSuspended);
	$("[id='items_form:selected_brand']").val(editBrand);

	$("[id='items_form:edit_item_code']").val(editItemCode);
	$("[id='items_form:edit_item_name']").val(editItemName);
	$("[id='items_form:edit_item_description']").val(editItemDescription);
	$("[id='items_form:edit_price']").val(editPrice);
	$("[id='items_form:edit_orig_location']").val(editOrigLocation);
	$("[id='items_form:edit_category']").val(editCategory);
	$("[id='items_form:edit_icon']").val(editIcon);
	$("[id='items_form:item_image']").attr("src", editIcon);
	$("[id='items_form:edit_suspended']").val(editSuspended);
	$("[id='items_form:edit_attributes']").val(editAttribute);
	$("[id='items_form:edit_brand']").val(editBrand);

	if (selectedValue == '') {
		alert("Please select a row first!");
	} else {
		$("#dialog_form_edit").dialog("open");
	}
	return false;
}

function createOnClick() {
	clearFields();
	$("#dialog_form_create").dialog("open");
	return false;

}

function clearFields() {

	$("[id='items_form:selected_value']").val('');
	$("[id='items_form:selected_item_code']").val('');
	$("[id='items_form:selected_item_name']").val('');
	$("[id='items_form:selected_item_description']").val('');
	$("[id='items_form:selected_price']").val('');
	$("[id='items_form:selected_orig_location']").val('');
	$("[id='items_form:selected_category']").val('');
	$("[id='items_form:selected_icon']").val('');
	$("[id='items_form:selected_attributes']").val('');
	$("[id='items_form:selected_suspended']").val('');
	$("[id='items_form:selected_brand']").val('');

	$("[id='items_form:edit_item_code']").val('');
	$("[id='items_form:edit_item_name']").val('');
	$("[id='items_form:edit_item_description']").val('');
	$("[id='items_form:edit_price']").val('');
	$("[id='items_form:edit_orig_location']").val('');
	$("[id='items_form:edit_category']").val('');
	$("[id='items_form:edit_icon']").val('');
	$("[id='items_form:edit_attributes']").val('');
	$("[id='items_form:edit_suspended']").val('');
	$("[id='items_form:edit_brand']").val('');

	$("[id='items_form:create_item_code']").val('');
	$("[id='items_form:create_item_name']").val('');
	$("[id='items_form:create_item_description']").val('');
	$("[id='items_form:create_price']").val('');
	$("[id='items_form:create_orig_location']").val('');
	$("[id='items_form:create_category']").val('');
	$("[id='items_form:create_icon']").val('');
	$("[id='items_form:create_attributes']").val('');
	$("[id='items_form:create_suspended']").val('');
	$("[id='items_form:item_image']").attr("src", '');
}

